package com.cn.customer.housekeeping.housekeepingb.ui;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.bean.BaseResp;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.IUserLoginView;
import com.cn.customer.housekeeping.housekeepingb.biz.personcenter.InterfacePresenter;
import com.cn.customer.housekeeping.housekeepingb.constant.Constants;
import com.cn.customer.housekeeping.housekeepingb.ui.base.BaseActivity;


/***
 *地点详情
 */
public class PlaceDetailsActivity extends BaseActivity implements IUserLoginView {
    private InterfacePresenter mInterfacePresenter;

    TextView tvwu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_placedetails);
        super.onCreate(savedInstanceState);
    }
    EditText tv_name;
    TextView tv_address,tv_banjing;
    RelativeLayout rl_banjing;
    @Override
    public void initViews() {
        mInterfacePresenter = new InterfacePresenter();
        mInterfacePresenter.attachView(this);
        tv_name=(EditText)findViewById(R.id.tv_name);
        tv_address=(TextView)findViewById(R.id.tv_address);
        tv_banjing=(TextView)findViewById(R.id.tv_banjing);
        rl_banjing=(RelativeLayout)findViewById(R.id.rl_banjing);

    }

    @Override
    public void initListeners() {
        rl_banjing.setOnClickListener(this);
    }

String Pname,Paddress,PLat,PLong;
    @Override
    public void initData() {
        Pname = getIntent().getExtras().getString(Constants.Pname);
        Paddress = getIntent().getExtras().getString(Constants.Paddress);
        PLat = getIntent().getExtras().getString(Constants.PLat);
        PLong = getIntent().getExtras().getString(Constants.PLong);

        tv_name.setText(Pname);
        tv_address.setText(Paddress);
    }

    @Override
    public void setHeader() {
        super.setHeader();
        rlTitle.setVisibility(View.VISIBLE);
        tvTopRighttitle.setVisibility(View.VISIBLE);
        tvTopTitle.setText("地点详情");
        tvTopRighttitle.setText("完成");

    }
    private void showPopwindow() {
        View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
        View popView = View.inflate(this, R.layout.pop_place_item, null);

    final     TextView tv_1 = (TextView) popView.findViewById(R.id.tv_1);
        final TextView tv_3 = (TextView) popView.findViewById(R.id.tv_3);
        final   TextView tv_5= (TextView) popView.findViewById(R.id.tv_5);
        final   TextView tv_10 = (TextView) popView.findViewById(R.id.tv_10);
        final   TextView tv_15 = (TextView) popView.findViewById(R.id.tv_15);
        final   TextView tv_20 = (TextView) popView.findViewById(R.id.tv_20);

        final PopupWindow popWindow = new PopupWindow(popView,  ViewGroup.LayoutParams.MATCH_PARENT,  ViewGroup.LayoutParams.WRAP_CONTENT);
        popWindow.setAnimationStyle(R.style.AnimBottom);
        popWindow.setFocusable(true);
        popWindow.setOutsideTouchable(false);// 设置同意在外点击消失

        View.OnClickListener listener = new View.OnClickListener() {
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.tv_1:
                        tv_banjing.setText(tv_1.getText().toString());
                        break;
                    case R.id.tv_3:
                        tv_banjing.setText(tv_3.getText().toString());
                        break;
                    case R.id.tv_5:
                        tv_banjing.setText(tv_5.getText().toString());
                        break;
                    case R.id.tv_10:
                        tv_banjing.setText(tv_10.getText().toString());
                        break;
                    case R.id.tv_15:
                        tv_banjing.setText(tv_15.getText().toString());
                        break;
                    case R.id.tv_20:
                        tv_banjing.setText(tv_20.getText().toString());
                        break;

                }
                popWindow.dismiss();
            }
        };

        tv_1.setOnClickListener(listener);
        tv_3  .setOnClickListener(listener);
        tv_5 .setOnClickListener(listener);
        tv_10   .setOnClickListener(listener);
        tv_15   .setOnClickListener(listener);
        tv_20  .setOnClickListener(listener);

        ColorDrawable dw = new ColorDrawable(0x30000000);
        popWindow.setBackgroundDrawable(dw);
        popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_banjing://服务半径
                showPopwindow();

                break;
            case R.id.tv_top_righttitle://完成
                    Intent intent = new Intent();
                    intent.putExtra("name", tv_name.getText().toString() );
                    intent.putExtra("address", Paddress );
                    intent.putExtra("Lat",PLat );
                    intent.putExtra("Long", PLong );
                    setResult(RESULT_OK, intent);
                    finish();

                break;

        }
        super.onClick(v);
    }    @Override
    public void onError(BaseResp s) {

    }

    @Override
    public void onSuccess(BaseResp s) {

    }

    @Override
    public void showLoading() {
        super.showLoading();
    }

    @Override
    public void hideLoading() {
        super.hideLoading();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
